//
//  UserInfoController.m
//  ChatForHot
//
//  Created by FLY on 2018/10/12.
//  Copyright © 2018年 FLY. All rights reserved.
//

#import "UserInfoController.h"
#import "BlankHeadView.h"
#import <Hyphenate/Hyphenate.h>
#import <CoreLocation/CoreLocation.h>
#import "UserHeadInfoCell.h"
#import "UserIntroductionCell.h"
#import "UserOthersCell.h"
#import "UserInfoGroundView.h"
#import "PhotoVaultCell.h"
#import "PersonalVipViewController.h"
#import "PreviewUserPhotoViewController.h"
#import "UITableView+NULLABL.h"
#import "ChatViewController.h"
#import "NoVipView.h"
#define PrivateType 10001

@interface UserInfoController ()<UITableViewDelegate,UITableViewDataSource,CLLocationManagerDelegate,PhotoVaultCellDelegate,UserInfoGroundViewDelegate,MWPhotoBrowserDelegate,NoVipViewDelegate>

@property (nonatomic, strong) UIButton *HOTCHATbackBtn;

@property (nonatomic, strong) UIButton *HOTCHATmoreBtn;

@property (nonatomic, strong) BlankHeadView *HOTCHATheadNullView;

@property (nonatomic, strong) CLLocationManager * HOTCHATLocation;

@property (nonatomic, strong) NSNumber* HOTCHATlongi;

@property (nonatomic, strong) NSNumber* HOTCHATlati;

@property (nonatomic, strong) UserInfoGroundView *HOTCHATbackView;

@property (nonatomic, assign) NSInteger HOTCHATphototype;

@property (nonatomic, strong) PreviewUserPhotoViewController *HOTCHATpreviewBrowser;

@property (nonatomic, strong) UIButton *HOTCHATchatBtn;

@property (nonatomic, strong) NoVipView *HOTCHATnoVipView;


@end

@implementation UserInfoController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.isHiddenNav = YES;
    
    if ([self.accountId isEqualToString:@""]) {
        self.accountId = self.userInfoModel.accountid;
    }
    
    //location requestdata
    [self HOTCHATbegainLocation];
    
    [self HOTCHATcmdMessagevisitors];
    
    [self HOTCHATyouHaveAvisitor];
}

- (void)HOTCHATInsertSubViews{
    
    [self.view addSubview:self.HOTCHATbackView];
    [self.view addSubview:self.HOTCHATtablewView];
    [self.view addSubview:self.HOTCHATbackBtn];
    [self.view addSubview:self.HOTCHATmoreBtn];
    [self.view addSubview:self.HOTCHATchatBtn];
    
    [self.HOTCHATbackBtn mas_updateConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.view).mas_offset(10);
        make.top.equalTo(self.view).mas_offset(22);
        make.width.height.mas_equalTo(32);
    }];
    [self.HOTCHATmoreBtn mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view).mas_offset(-10);
        make.width.height.mas_equalTo(32);
        make.centerY.equalTo(self.HOTCHATbackBtn);
    }];
    
    [self.HOTCHATbackView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.height.mas_equalTo(HOTCHATUIWIDTH-10);
    }];
    [self.HOTCHATtablewView mas_updateConstraints:^(MASConstraintMaker *make) {

        make.edges.equalTo(self.view);
    }];
    [self.HOTCHATchatBtn mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view).mas_offset(-18);
        make.centerX.equalTo(self.view.mas_left).offset(HOTCHATUIWIDTH * 1 / 2);
    }];
    
}
- (void)HOTCHATrequestUserinfo{
    
    [self HOTCHATstartLoading];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    NSString * userId = @"";
    NSString * requestUrl = @"";
    if (self.isIMid) {
        
        userId = self.IMID;
        requestUrl = IMID_ACCOUNTINFO_URL;
        [dic setValue:userId forKey:@"accountNumber"];
    }else{
        
        userId = self.accountId;
        requestUrl = ACCOUNTINFO_URL;
        [dic setValue:userId forKey:@"accountid"];
    }
    
    [dic setValue:self.HOTCHATlongi forKey:@"muLongitud"];
    [dic setValue:self.HOTCHATlati forKey:@"muLatitude"];
    
    [NetWorkTool HOTCHATRequestWithStringURL:requestUrl progress:^(NSProgress * _Nonnull progress) {
        
    } RequestWay:@"POST" Parma:dic SuccessBlock:^(BOOL isSucess, NSDictionary * _Nonnull resultDictionary) {
        [self HOTCHATstopLoading];
        if ([resultDictionary[@"code"] integerValue] == 0) {
            
            UserInfoModel *model = [[UserInfoModel alloc]init];
            [model setValuesForKeysWithDictionary:resultDictionary[@"data"]];
            self.userInfoModel = model;
            
            [self HOTCHATreloadDataAndRefreshUI];
            if (self.isIMid) {
                self.IMID = model.IMUser;
            }else{
                self.accountId = model.accountid;
            }
        }
        
    } FailureBlock:^(NSError * _Nonnull error) {
        [self HOTCHATstopLoading];
    }];
}
- (void)HOTCHATreloadDataAndRefreshUI{
    
    [self.HOTCHATtablewView reloadData];
    self.HOTCHATbackView.model = self.userInfoModel;
    
}
//show pic or video
- (void)HOTCHATlookVideo:(NSString *)vid lookBlock:(void (^)(void))lookBlock{
    
    if (HOTCHATAPPINFO.isVIP.integerValue == 1) {
        //vip
        lookBlock();
    }else{
        //not vip
        [self HOTCHATneedBecameVipAlert];
    }
}
- (void)HOTCHATlookPhotoIndex:(NSInteger)index type:(NSInteger)type{
    
    self.HOTCHATphototype = type;
    //private
    NSInteger vpindex;
    if (type == PrivateType) {
        vpindex = index - self.userInfoModel.privateVideo.count;
    }else{
        if (self.userInfoModel.commonPic.count == 0) {
            
            return;
        }
        vpindex = index - self.userInfoModel.commonVideo.count;
    }
    if (HOTCHATAPPINFO.isVIP.integerValue == 1 || type != PrivateType) {
        
        [self HOTCHATpreviewPhotoIndex:index];
        return;
    }else{
        
        [self HOTCHATneedBecameVipAlert];
        return;
    }
//    if (vpindex < 0 || vpindex >= self.userInfoModel.privatePic.count) {
//        
//        return;
//    }
    
}
- (void)HOTCHATpreviewPhotoIndex:(NSInteger )index{
    
    [self.HOTCHATpreviewBrowser reloadData];
    [self.HOTCHATpreviewBrowser setCurrentPhotoIndex:index];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self.HOTCHATpreviewBrowser];
    [self presentViewController:nav animated:YES completion:nil];
}
//browserDelegate
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser{
    
    if (self.HOTCHATphototype == PrivateType) {
        //private photos
        return self.userInfoModel.privatePic.count;
    }else{
        //common pic
        return self.userInfoModel.commonPic.count;
    }
}
- (id<MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index{
    
    NSString *photoUrl;
    if (self.HOTCHATphototype == PrivateType) {
        
        photoUrl = [self.userInfoModel.privatePic objectAtIndex:index];
    }
    else{
        
        photoUrl = [self.userInfoModel.commonPic objectAtIndex:index];
    }
    
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",APIHEADER,photoUrl]];
    return [MWPhoto photoWithURL:url];
    
}
- (void)HOTCHATneedBecameVipAlert{
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:NSLocalizedString(@"StrN044", nil) preferredStyle:(UIAlertControllerStyleAlert)];
    
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"StrN025", nil) style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    UIAlertAction *vipa = [UIAlertAction actionWithTitle:NSLocalizedString(@"StrN045", nil) style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        
        PersonalVipViewController *VIPVC = [[PersonalVipViewController alloc]init];
        [self.navigationController pushViewController:VIPVC animated:YES];
    }];
    
    [alertController addAction:cancel];
    [alertController addAction:vipa];
    
    [self presentViewController:alertController animated:YES completion:nil];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
//    NSLog(@"%lf",scrollView.contentOffset.y);
    self.HOTCHATbackView.offSetY = scrollView.contentOffset.y;
}
#pragma tableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 5;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section == 0) {
        //user info
        return 1;
    }else if(section == 1){
        //privte pic or udio
        if (self.userInfoModel.privteArr.count > 0) {
            return 1;
        }
        return 0;
    }else if (section == 2){
        //introducton
        return 1;
    }else if (section == 3){
        
        return 3;
    }else if (section == 4){
        //numbers
        return 4;
    }
    return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        //heder
        UserHeadInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UserHeadInfoCell"];
        if (!cell) {
            
            cell = [[UserHeadInfoCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UserHeadInfoCell"];
        }
        cell.model = self.userInfoModel;
        return cell;
    }else if (indexPath.section == 1) {
        //heder
        PhotoVaultCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PhotoVaultCell"  forIndexPath:indexPath];
//        if (!cell) {
//
//            cell = [[PhotoVaultCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"PhotoVaultCell"];
//        }
        cell.delegate = self;
        cell.model = self.userInfoModel;
        return cell;
    }
    else if (indexPath.section == 2) {
        //heder
        UserIntroductionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UserIntroductionCell"];
//        if (!cell) {
//
//            cell = [[UserIntroductionCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UserIntroductionCell"];
//        }
        cell.model = self.userInfoModel;
        return cell;
    }else if (indexPath.section == 3){
        //other
        UserOthersCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UserOthersCell" forIndexPath:indexPath];
        [cell HOTCHATgetModel:self.userInfoModel section:indexPath.section index:indexPath.row];
        cell.model = self.userInfoModel;
        cell.indexPath = indexPath;
        return cell;
    }
    else if (indexPath.section == 4){
        //other
        UserOthersCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UserOthersCell" forIndexPath:indexPath];
        [cell HOTCHATgetModel:self.userInfoModel section:indexPath.section index:indexPath.row];
        cell.model = self.userInfoModel;
        cell.indexPath = indexPath;
        return cell;
    }
    
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.section) {
        case 0:
            return 95;
            break;
        case 1:
            return 135;
            break;
        case 2:
            
            return [UserIntroductionCell HOTCHATcaculateCellHeightWithModel:self.userInfoModel];;
            break;
        case 3:
            return 45;
            break;
        case 4:
            return 40;
            break;
            
        default:
            break;
    }
    return 100;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 4) {
        return 10;
    }
    return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    return [[UIView alloc] init];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [[UIView alloc] init];
}
- (void)HOTCHATmoreAction{
    
    //moreaction
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction *reportAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"StrN030", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        [self HOTCHATreportMethod];
    }];
    UIAlertAction *blockAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"StrN031", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        [self HOTCHATblockMethod];
    }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"StrN025", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertController addAction:reportAction];
    [alertController addAction:blockAction];
    [alertController addAction:cancelAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
}
- (void)HOTCHATreportMethod{
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:(UIAlertControllerStyleActionSheet)];

    UIAlertAction *action1 = [UIAlertAction actionWithTitle:NSLocalizedString(@"StrN032", nil) style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        
        [self HOTCHATreportWithTitle:NSLocalizedString(@"StrN032", nil)];
    }];
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:NSLocalizedString(@"StrN033", nil) style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        
        [self HOTCHATreportWithTitle:NSLocalizedString(@"StrN033", nil)];
    }];
    UIAlertAction *action3 = [UIAlertAction actionWithTitle:NSLocalizedString(@"StrN034", nil) style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        
        [self HOTCHATreportWithTitle:NSLocalizedString(@"StrN034", nil)];
    }];
    UIAlertAction *action4 = [UIAlertAction actionWithTitle:NSLocalizedString(@"StrN035", nil) style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        
        [self HOTCHATreportWithTitle:NSLocalizedString(@"StrN035", nil)];
    }];
    UIAlertAction *action5 = [UIAlertAction actionWithTitle:NSLocalizedString(@"StrN036", nil) style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        
        [self HOTCHATreportWithTitle:NSLocalizedString(@"StrN036", nil)];
    }];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"StrN025", nil) style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    [alertController addAction:action1];
    [alertController addAction:action2];
    [alertController addAction:action3];
    [alertController addAction:action4];
    [alertController addAction:action5];
    [alertController addAction:cancelAction];

    [self presentViewController:alertController animated:YES completion:nil];

}
- (void)HOTCHATreportWithTitle:(NSString *)title{
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setValue:HOTCHATAPPINFO.accountid forKey:@"cpAccountid"];
    [dic setValue:self.userInfoModel.accountid forKey:@"cpBeAccountid"];
    [dic setValue:[NSString stringWithFormat:@"%@",title] forKey:@"content"];
    
    [NetWorkTool HOTCHATRequestWithStringURL:REPORT_URL progress:^(NSProgress * _Nonnull progress) {
        
    } RequestWay:@"POST" Parma:dic SuccessBlock:^(BOOL isSucess, NSDictionary * _Nonnull resultDictionary) {
        
    } FailureBlock:^(NSError * _Nonnull error) {
        
    }];
    [self HOTCHATshowMessage:NSLocalizedString(@"StrN058", nil)];
}
- (void)HOTCHATblockMethod{
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    NSString *userIMid = self.userInfoModel.IMUser;
    NSString *userId = self.userInfoModel.accountid;
    if (self.IMID.length > 0) {
        
        userIMid = self.IMID;
    }else if (self.accountId.length > 0){
        
        userId = self.accountId;
    }else {
        return;
    }
    [dic setValue:HOTCHATAPPINFO.accountid forKey:@"shieldingAccountid"];
    [dic setValue:userId forKey:@"beShieldingAccountid"];
    
    [NetWorkTool HOTCHATRequestWithStringURL:BLOCK_URL progress:^(NSProgress * _Nonnull progress) {
        
    } RequestWay:@"POST" Parma:dic SuccessBlock:^(BOOL isSucess, NSDictionary * _Nonnull resultDictionary) {
        if ([resultDictionary[@"code"] integerValue] == 0) {
            
            [[EMClient sharedClient].contactManager addUserToBlackList:userIMid completion:^(NSString *aUsername, EMError *aError) {
                if (!aError) {
                    //successful
                }
            }];
            
            [self HOTCHATshowMessage:NSLocalizedString(@"StrN037", nil)];
        }
    } FailureBlock:^(NSError * _Nonnull error) {
        
    }];
    
}
#pragma location
- (void)HOTCHATbegainLocation{
    
    self.HOTCHATLocation = [[CLLocationManager alloc]init];
    self.HOTCHATLocation.delegate = self;
    [self.HOTCHATLocation requestWhenInUseAuthorization];
    [self.HOTCHATLocation startUpdatingLocation];
    
}
// CLLocationManager delegate
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
    
    // 1.get userinfo
    CLLocation *location = [locations lastObject];
    CLLocationCoordinate2D coordinate = location.coordinate;
    
    self.HOTCHATlongi = [NSNumber numberWithDouble:coordinate.longitude];
    self.HOTCHATlati = [NSNumber numberWithDouble:coordinate.latitude];
    
    // stop location
    [manager stopUpdatingLocation];
    
    [self HOTCHATrequestUserinfo];
}
- (void)locationManager:(CLLocationManager *)manager
       didFailWithError:(NSError *)error
{
    if (error.code == kCLErrorDenied) {
        //error
    }
    [self HOTCHATrequestUserinfo];
}

//lazzy
- (UIButton *)HOTCHATbackBtn{
    
    if (_HOTCHATbackBtn == nil) {
        
        _HOTCHATbackBtn = [[UIButton alloc]init];
        [_HOTCHATbackBtn setBackgroundImage:[UIImage imageNamed:@"l_back"] forState:UIControlStateNormal];
        [_HOTCHATbackBtn setBackgroundImage:[UIImage imageNamed:@"l_back_hig"] forState:UIControlStateHighlighted];
        [_HOTCHATbackBtn addTarget:self action:@selector(HOTCHATbackClcik) forControlEvents:UIControlEventTouchUpInside];
    }
    return _HOTCHATbackBtn;
}
- (UIButton *)HOTCHATmoreBtn{
    
    if (_HOTCHATmoreBtn == nil) {
        
        _HOTCHATmoreBtn = [[UIButton alloc]init];
        [_HOTCHATmoreBtn setBackgroundImage:[UIImage imageNamed:@"userinfo_more"] forState:UIControlStateNormal];
        [_HOTCHATmoreBtn setBackgroundImage:[UIImage imageNamed:@"userinfo_more_hig"] forState:UIControlStateHighlighted];
        [_HOTCHATmoreBtn addTarget:self action:@selector(HOTCHATmoreAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _HOTCHATmoreBtn;
}
- (BlankHeadView *)HOTCHATheadNullView{
    
    if (_HOTCHATheadNullView == nil) {
        
        _HOTCHATheadNullView = [[BlankHeadView alloc]init];
        _HOTCHATheadNullView.userInteractionEnabled = YES;
        _HOTCHATheadNullView.frame = CGRectMake(0, 0, HOTCHATUIWIDTH, HOTCHATUIWIDTH-20);
        
    }
    return _HOTCHATheadNullView;
}
- (UIButton *)HOTCHATchatBtn{
    
    if (_HOTCHATchatBtn ==  nil) {
        
        _HOTCHATchatBtn = [[UIButton alloc]init];
        
        [_HOTCHATchatBtn setBackgroundImage:[UIImage imageNamed:@"details_ic_message"] forState:UIControlStateNormal];
        [_HOTCHATchatBtn setBackgroundImage:[UIImage imageNamed:@"details_ic_message_hig"] forState:UIControlStateHighlighted];
        [_HOTCHATchatBtn addTarget:self action:@selector(HOTCHATgoChatAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _HOTCHATchatBtn;
}
- (UITableView *)HOTCHATtablewView{
    
    if (_HOTCHATtablewView == nil) {
        
        _HOTCHATtablewView = [[UITableView alloc]init];
        _HOTCHATtablewView.backgroundColor = [UIColor clearColor];
        _HOTCHATtablewView.delegate = self;
        _HOTCHATtablewView.dataSource = self;
        _HOTCHATtablewView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _HOTCHATtablewView.bounces = NO;
        _HOTCHATtablewView.tableHeaderView = self.HOTCHATheadNullView;
        _HOTCHATtablewView.showsVerticalScrollIndicator = NO;
        _HOTCHATtablewView.userInteractionEnabled = YES;
        _HOTCHATtablewView.isNullAbl = YES;
        //no click
        _HOTCHATtablewView.allowsSelection=NO;
        [self.HOTCHATheadNullView mas_updateConstraints:^(MASConstraintMaker *make) {
            
            make.left.top.right.equalTo(self->_HOTCHATtablewView);
            make.width.equalTo(self->_HOTCHATtablewView);
            make.height.mas_equalTo(HOTCHATUIWIDTH-20);
        }];
        UIView *fvv = [[UIView alloc] init];
        fvv.frame = CGRectMake(0, 0, HOTCHATUIWIDTH, HOTCHATUIWIDTH - 200);
        fvv.backgroundColor = [UIColor whiteColor];
        _HOTCHATtablewView.tableFooterView = fvv;
        [_HOTCHATtablewView registerClass:[UserHeadInfoCell class] forCellReuseIdentifier:@"UserHeadInfoCell"];
        [_HOTCHATtablewView registerClass:[UserIntroductionCell class] forCellReuseIdentifier:@"UserIntroductionCell"];
        [_HOTCHATtablewView registerClass:[UserOthersCell class] forCellReuseIdentifier:@"UserOthersCell"];
        [_HOTCHATtablewView registerClass:[PhotoVaultCell class] forCellReuseIdentifier:@"PhotoVaultCell"];
        if (@available(iOS 11.0, *)) {
            _HOTCHATtablewView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        } else {
            // Fallback on earlier versions
        }
    }
    return _HOTCHATtablewView;
}
- (UserInfoGroundView *)HOTCHATbackView{
    
    if (_HOTCHATbackView == nil) {
        
        _HOTCHATbackView = [[UserInfoGroundView alloc]init];
        _HOTCHATbackView.delegate = self;
    }
    return _HOTCHATbackView;
}
- (PreviewUserPhotoViewController *)HOTCHATpreviewBrowser{
    
    if (_HOTCHATpreviewBrowser == nil) {
        
        _HOTCHATpreviewBrowser = [[PreviewUserPhotoViewController alloc] initWithDelegate:self];
        _HOTCHATpreviewBrowser.displayActionButton = NO;
        _HOTCHATpreviewBrowser.displayNavArrows = YES;
        _HOTCHATpreviewBrowser.displaySelectionButtons = NO;
        _HOTCHATpreviewBrowser.alwaysShowControls = NO;
        _HOTCHATpreviewBrowser.zoomPhotosToFill = YES;
        _HOTCHATpreviewBrowser.enableGrid = NO;
        _HOTCHATpreviewBrowser.startOnGrid = NO;
        
        _HOTCHATpreviewBrowser.isSelf = NO;
        [_HOTCHATpreviewBrowser setCurrentPhotoIndex:0];
    }
    return _HOTCHATpreviewBrowser;
}
- (void)HOTCHATbackClcik{
    
    if (_isSayhello) {
        
        [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    }else{
        
        [self.navigationController popViewControllerAnimated:YES];
    }
}
- (void)HOTCHATgoChatAction{
    
    if (self.isIMid) {
        [self HOTCHATbackClcik];
        return;
    }
    ChatViewController *chatVC = [[ChatViewController alloc] initWithConversationChatter:self.userInfoModel.IMUser conversationType:EMConversationTypeChat];
    chatVC.title = self.userInfoModel.nickName;
    [self.navigationController pushViewController:chatVC animated:YES];
}
- (void)HOTCHATcmdMessagevisitors{
    if (self.IMID.length == 0) {
        
        return;
    }
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setValue:HOTCHATAPPINFO.accountid forKey:@"accountid"];
    [dic setValue:HOTCHATAPPINFO.nickName forKey:@"nickName"];
    [dic setValue:HOTCHATAPPINFO.headPic forKey:@"headPic"];
    [dic setValue:HOTCHATAPPINFO.IMUser forKey:@"IMUser"];
    [dic setValue:HOTCHATAPPINFO.other forKey:@"other"];
    [dic setValue:HOTCHATAPPINFO.code forKey:@"vip"];
    
    [NetWorkTool HOTCHATsendCmdMessageToUser:self.IMID dic:dic];
}
- (void)HOTCHATyouHaveAvisitor{
    
    NSString *visitorId = @"";
    if (self.userInfoModel) {
        visitorId = self.userInfoModel.accountNumber;
    }else{
        visitorId = self.IMID;
    }
    
    if (visitorId.length > 0) {
        NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
        [dic setValue:visitorId forKey:@"accountNumber"];
        
        [dic setValue:NSLocalizedString(@"StrN047", @"Visitor") forKey:@"title"];
        [dic setValue:NSLocalizedString(@"StrN057", @"You have a new visitor!Click to view") forKey:@"content"];
        
        [NetWorkTool HOTCHATRequestWithStringURL:PUSHMESSAGE_URL progress:^(NSProgress * _Nonnull progress) {
            
        } RequestWay:@"POST" Parma:dic SuccessBlock:^(BOOL isSucess, NSDictionary * _Nonnull resultDictionary) {
            
        } FailureBlock:^(NSError * _Nonnull error) {
            
        }];
    }
}
@end
